package Draw0512;

import javax.swing.*;
import java.awt.*;

public class DrawUIV1_1 extends JFrame{
    DrawListenerV1_1 d1 = new DrawListenerV1_1();
    public void showUI(){
        this.setTitle("画图板V1.1");
        this.setSize(800,700);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setLayout(new FlowLayout());

        String[] strs = {"直线","矩形","圆形", "实心矩形", "实心圆形",
                "等腰三角形", "三角形", "多边形", "橡皮擦",
                "递归仿真峰线", "迭代分形"
        };

        for (int i = 0; i < strs.length; i++) {
            JButton btn = new JButton();
            btn.setText(strs[i]);
            this.add(btn);
            btn.addActionListener(d1);//一开始没加，导致g为空
        }
        Color[] colors = {
                Color.BLACK, Color.WHITE, Color.GRAY, Color.LIGHT_GRAY, Color.DARK_GRAY,
                Color.RED, Color.GREEN, Color.BLUE, Color.ORANGE, Color.YELLOW, Color.MAGENTA,
                Color.PINK, Color.CYAN, new Color(166, 85, 0)
        };

        Dimension cbtnDim = new Dimension(30, 30);//统一大小

        for (int i = 0; i < colors.length; i++) {
            JButton btn = new JButton();
            btn.setBackground(colors[i]);
            btn.setPreferredSize(cbtnDim);
            this.add(btn);
            btn.addActionListener(d1);
        }
        this.setVisible(true);
        Graphics g = this.getGraphics();
        this.addMouseListener(d1);
        d1.g = g;
        d1.jf = this;
    }

    @Override
    public void paint(Graphics g){
        super.paint(g);

        g.fillRect(100, 100, 80, 28);

        for (int i = 0; i < d1.shapeSize; i++) {
            Shape shape = d1.shapeList[i];
            shape.drawShape();
        }
    }
}
